package org.htmlparser.parserapplications.filterbuilder.wrappers;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.parserapplications.filterbuilder.Filter;
import org.htmlparser.parserapplications.filterbuilder.SubFilterList;

public class AndFilterWrapper extends Filter
{
  protected SubFilterList mContainer;
  protected AndFilter mFilter = new AndFilter();

  public AndFilterWrapper()
  {
    this.mContainer = new SubFilterList(this, "Predicates", 0);
    add(this.mContainer);
  }

  public boolean accept(Node paramNode)
  {
    return this.mFilter.accept(paramNode);
  }

  public String getDescription()
  {
    return "And";
  }

  public String getIconSpec()
  {
    return "images/AndFilter.gif";
  }

  public NodeFilter getNodeFilter()
  {
    AndFilter localAndFilter = new AndFilter();
    NodeFilter[] arrayOfNodeFilter1 = this.mFilter.getPredicates();
    NodeFilter[] arrayOfNodeFilter2 = new NodeFilter[arrayOfNodeFilter1.length];
    for (int i = 0; i < arrayOfNodeFilter1.length; ++i)
      arrayOfNodeFilter2[i] = ((Filter)arrayOfNodeFilter1[i]).getNodeFilter();
    localAndFilter.setPredicates(arrayOfNodeFilter2);
    return localAndFilter;
  }

  public NodeFilter[] getSubNodeFilters()
  {
    return this.mFilter.getPredicates();
  }

  public void setNodeFilter(NodeFilter paramNodeFilter, Parser paramParser)
  {
    this.mFilter = ((AndFilter)paramNodeFilter);
  }

  public void setSubNodeFilters(NodeFilter[] paramArrayOfNodeFilter)
  {
    this.mFilter.setPredicates(paramArrayOfNodeFilter);
  }

  public String toJavaCode(StringBuffer paramStringBuffer, int[] paramArrayOfInt)
  {
    NodeFilter[] arrayOfNodeFilter = this.mFilter.getPredicates();
    String str1 = null;
    if (arrayOfNodeFilter.length != 0)
    {
      String[] arrayOfString = new String[arrayOfNodeFilter.length];
      for (int j = 0; j < arrayOfNodeFilter.length; ++j)
        arrayOfString[j] = ((Filter)arrayOfNodeFilter[j]).toJavaCode(paramStringBuffer, paramArrayOfInt);
      StringBuffer localStringBuffer2 = new StringBuffer().append("array");
      int k = paramArrayOfInt[2];
      paramArrayOfInt[2] = (k + 1);
      str1 = k;
      spaces(paramStringBuffer, paramArrayOfInt[0]);
      paramStringBuffer.append("NodeFilter[] ");
      paramStringBuffer.append(str1);
      paramStringBuffer.append(" = new NodeFilter[");
      paramStringBuffer.append(arrayOfNodeFilter.length);
      paramStringBuffer.append("];");
      newline(paramStringBuffer);
      for (int l = 0; l < arrayOfNodeFilter.length; ++l)
      {
        spaces(paramStringBuffer, paramArrayOfInt[0]);
        paramStringBuffer.append(str1);
        paramStringBuffer.append("[");
        paramStringBuffer.append(l);
        paramStringBuffer.append("] = ");
        paramStringBuffer.append(arrayOfString[l]);
        paramStringBuffer.append(";");
        newline(paramStringBuffer);
      }
    }
    StringBuffer localStringBuffer1 = new StringBuffer().append("filter");
    int i = paramArrayOfInt[1];
    paramArrayOfInt[1] = (i + 1);
    String str2 = i;
    spaces(paramStringBuffer, paramArrayOfInt[0]);
    paramStringBuffer.append("AndFilter ");
    paramStringBuffer.append(str2);
    paramStringBuffer.append(" = new AndFilter ();");
    newline(paramStringBuffer);
    if (arrayOfNodeFilter.length != 0)
    {
      spaces(paramStringBuffer, paramArrayOfInt[0]);
      paramStringBuffer.append(str2);
      paramStringBuffer.append(".setPredicates (");
      paramStringBuffer.append(str1);
      paramStringBuffer.append(");");
      newline(paramStringBuffer);
    }
    return str2;
  }
}